/*
 * @Author: thinker_cy
 * @Date: 2025-07-02 16:42:04
 * @FilePath: \weimai-admin\vite.config.js
 * @Description: 
 */
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import tailwindcss from '@tailwindcss/vite'
import AutoImport from 'unplugin-auto-import/vite'

// https://vite.dev/config/
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd())
  return {
    plugins: [
      vue(),
      tailwindcss(),
      AutoImport({
        include: [
          /\.[tj]sx?$/,
          /\.vue$/,
          /\.vue\?vue/,
          /\.md$/,
        ],
        imports: ['vue','vue-router', 'pinia', '@vueuse/core'],
        dts: './auto-imports.d.ts'
      })
    ],
    server: {
      host: '0.0.0.0',
      open: env.VITE_AUTO_OPEN === 'true',
      proxy: {
        '/admin': {
          target: env.VITE_BASE_URL,
          changeOrigin: true,
          // 如果后端没有 /api 前缀，可取消注释进行路径重写
          // rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "@/styles/variables" as *;`,
        },
      },
    },
    define: {
      'process.env': {
        'VITE_BASE_API': env.VITE_BASE_API
      }
    },
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      }
    },
    build: {
      outDir: env.VITE_OUTPUT_DIR || 'dist'
    }
  }
})
